﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls;
using Silvermoon.Controls.Base;
using Silvermoon.Controls.Classes;
using Silvermoon.Controls.Interfaces;

namespace Silvermoon.Controls
{
    /// <summary>
    /// A dialog button is used to be added to dialogs to automatically raise a Hide event with the associated Result without having to add an event handler that would
    /// perform that job.
    /// </summary>
    public class DialogButton : Button, IDialogControl
    {

        public DialogButton()
            : base()
        {
            Result = DialogResult.OK;
        }


        /// <summary>
        /// Gets or sets the result for the dialog.
        /// </summary>
        public DialogResult Result { get; set; }

        protected override void OnClick()
        {
            IDialogControl dc = (IDialogControl)this;

            DialogBase dlg = dc.Dialog;
            if (dlg != null)
            {
                dlg.Result = this.Result;
                dlg.Hide();
            }
            base.OnClick();
        }

        /// <summary>
        /// Gets the dialog to which this control is added, otherwise null.
        /// </summary>
        public DialogBase Dialog
        {
            get { return ((IDialogControl)this).Dialog; }
        }

        #region IDialogControl Members

        DialogBase IDialogControl.Dialog { get; set; }

        #endregion
    }
}
